package ddd.ajava.chapter6.question3;

import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;

public class ThreadMonitor implements Callable<Long>{
	private ConcurrentHashMap<ImageAnalyzeThread, Integer> conThread=null;

	public ThreadMonitor(ConcurrentHashMap<ImageAnalyzeThread, Integer> conThread) {
		this.conThread=conThread;
	}
	
	@Override
	public Long call() throws Exception {
		while(true){
			if(conThread.size()<=0){
				return System.currentTimeMillis();
			}
			Set<ImageAnalyzeThread> keys=conThread.keySet();
			for(ImageAnalyzeThread t:keys){
				if(!t.isAlive()){
					conThread.remove(t);
				}
			}
		}
	}
}
